package com.kangfawei.io;

import java.io.*;

/**
 * @author 康发伟
 * 文件缓冲字符流的使用
 */
public class BufferedTest02 {
    public static void main(String[] args) {
        String src = "E:/IO_src/test01.txt";
        String target = "E:/IO_target/test01.txt";

        copy(src,target);
    }

    /**
     * 文件拷贝方法  只适用于文本文档
     * @param src
     * @param target
     */
    public static void copy(String src,String target){
        try(BufferedReader reader = new BufferedReader(new FileReader(src));
            BufferedWriter writer = new BufferedWriter(new FileWriter(target))){
            String line = null;
            // 逐行读取
            while((line = reader.readLine()) != null){
                // 逐行写出
                writer.write(line);
                writer.newLine(); //每行加一个换行符
            }
            writer.flush();

        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
